using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using Sedna.Core.Security;
using log4net;

namespace Sedna.Core.Controller.Configurations
{
    public class QuantityDataTranslator : IDataTranslator
    {
        private bool clearIfZero = false;
        private object defaultValue = 0;

        # region Properties

        public bool ClearIfZero
        {
            set { clearIfZero = value; }
        }

        public object DefaultValue
        {
            set { defaultValue = value; }
        }

        # endregion

        public object Translate(Control control, object value)
        {
            return Translate(control, value, null);
        }
        
        public object Translate(Control control, object value, Type targetType)
        {
            if (value == null)
            {
                value = defaultValue;
            }

            string strValue = value.ToString();

            if (clearIfZero && strValue.Equals("0"))
                strValue = string.Empty;
            
            return strValue;
        }
    }
}
